package com.jy.modules.cims.component.common.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.data.common.dao.TCMmCooperorgDealDao;
import com.jy.modules.cims.data.common.dao.TCMmCostaccountViewDao;
import com.jy.modules.cims.data.common.dao.TCMmDealCostDao;
import com.jy.modules.cims.data.common.dto.TCMmCooperorgDealDTO;
import com.jy.modules.cims.data.common.dto.TCMmCostaccountViewDTO;
import com.jy.modules.cims.data.common.dto.TCMmDealCostDTO;
import com.jy.platform.core.common.BaseDTO;


/**
 * @classname: TCMmCostaccountViewService
 * @description: 定义  COSTACCOUNT_VIEW 实现类
 * @author:  dell
 */
@Service("com.jy.modules.cims.component.common.service.TCMmCostaccountViewService")
public class TCMmCostaccountViewService implements Serializable {

    private static final long serialVersionUID = 1L;
    
	@Autowired
	private TCMmCostaccountViewDao dao;
	@Autowired
	private TCMmDealCostDao dealCostdao;
	@Autowired
	private TCMmCooperorgDealDao cooperorgDealDao;

	/**
     * @author dell
     * @description: 分页查询 COSTACCOUNT_VIEW列表
     * @date 2015-02-02 20:26:25
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmCostaccountViewDTO> searchCostaccountViewByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmCostaccountViewDTO> dataList =  dao.searchCostaccountViewByPaging(searchParams);
		return dataList;
	}
	/**
     * @author dell
     * @description: 按条件查询COSTACCOUNT_VIEW列表
     * @date 2015-02-02 20:26:25
     * @param searchParams 条件
     * @return
     * @throws
     */
	public List<TCMmCostaccountViewDTO> searchCostaccountView(Map<String,Object> searchParams) throws Exception {
	    List<TCMmCostaccountViewDTO> dataList = dao.searchCostaccountView(searchParams);
        return dataList;
    }
	/**
     * @author dell
     * @description: 查询COSTACCOUNT_VIEW对象
     * @date 2015-02-02 20:26:25
     * @param id
     * @return
     * @throws
     */ 
	public TCMmCostaccountViewDTO queryCostaccountViewByPrimaryKey(String id) throws Exception {
		
		TCMmCostaccountViewDTO dto = dao.findCostaccountViewByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmCostaccountViewDTO();
		
		return dto;
		
	}

	/**
     * @title: insertCostaccountView
     * @author dell
     * @description: 新增 COSTACCOUNT_VIEW对象
     * @date 2015-02-02 20:26:25
     * @param dto
     * @return
     * @throws
     */
	@SuppressWarnings("all")
	public Long insertCostaccountView(TCMmCostaccountViewDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		int count = dao.insertCostaccountView(paramMap);
		
		TCMmCostaccountViewDTO resultDto = (TCMmCostaccountViewDTO) paramMap.get("dto");
		Long keyId = resultDto.getId();
		return keyId;
	}
	/**
     * @title: updateCostaccountView
     * @author dell
     * @description: 修改 COSTACCOUNT_VIEW对象
     * @date 2015-02-02 20:26:25
     * @param paramMap
     * @return
     * @throws
     */
	public void updateCostaccountView(TCMmCostaccountViewDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		dao.updateCostaccountView(paramMap);
	}
	/**
     * @title: deleteCostaccountViewByPrimaryKey
     * @author dell
     * @description: 删除 COSTACCOUNT_VIEW,按主键
     * @date 2015-02-02 20:26:25
     * @param paramMap
     * @throws
     */ 
	public void deleteCostaccountViewByPrimaryKey(BaseDTO baseDto,String ids) throws Exception {
		if(StringUtils.isEmpty(ids)) throw new Exception("删除失败！传入的参数主键为null");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", baseDto);
		paramMap.put("ids", ids);
		dao.deleteCostaccountViewByPrimaryKey(paramMap);
	}
	
	/**
     * @title: insertTCMmCostdealAdOrgdeal
     * @author zhuwenbin
     * @description: 费用结算添加交易结算表以及合作机构交易表
     * @date 2015-02-04 10:55:25
     * @param dealCostDto，orgdealDto
     * @throws
     */ 
	public void insertTCMmCostdealAdOrgdeal(TCMmDealCostDTO dealCostDto,TCMmCooperorgDealDTO orgdealDto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dealCostDto);
		dealCostdao.insertTCMmDealCost(paramMap);
		paramMap.put("dto", orgdealDto);
		cooperorgDealDao.insertTCMmCooperorgDeal(paramMap);
		
	}

}

